using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Example.Business;

namespace www
{
    public partial class Search_ByCountry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink l = (HyperLink)e.Item.FindControl("RegionLabel");
            if (e.Item.DataItem != null)
            {
                Region r = (Region)e.Item.DataItem;
                l.Text = r.Name;
                l.NavigateUrl = "~/Search/ByRegion.aspx?r=" + r.RegionId;
            }
            else
            {
                l.Text = "No regions found";
            }
        }
        protected void CountryDataSource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            e.Entities = CountryCollection.FetchAll();
        }
        protected void RegionDataSource_Select(object sender, NBusiness.Data.Web.SelectEntityEventArgs e)
        {
            int countryId;
            if (int.TryParse(Request["c"], out countryId) && countryId > 0)
            {
                e.Entities = RegionCollection.FetchByCountry(countryId);
            }
            else if (int.TryParse(DropDownList1.SelectedValue, out countryId) && countryId > 0)
            {
                e.Entities = RegionCollection.FetchByCountry(countryId);
            }
        }
        protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            int countryId;
            if (int.TryParse(Request["c"], out countryId) && countryId > 0)
            {
                DropDownList1.SelectedValue = countryId.ToString();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Search/ByCountry.aspx?c=" + DropDownList1.SelectedValue);
        }
    }
}